<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	'Anggota'=>array('user/semua'),
	User::model()->findByPk($model->id)->nama,
);

$this->pageTitle=Yii::app()->name . " - Lihat Profil";

?>

<div class="kolom-1">
	<h1 class="judul-halaman"><?php echo $model->id==Yii::app()->user->id ? "PROFIL SAYA" : "PROFIL ".User::model()->findByPk($model->id)->nama; ?></h1>
	<div class="latar-putih">
		 <div id="statusMsg">
			<?php if(Yii::app()->user->hasFlash('success')):?>
				<div class="alert alert-success">
					<?php echo Yii::app()->user->getFlash('success'); ?>
				</div>
			<?php endif; ?>
			 
			<?php if(Yii::app()->user->hasFlash('error')):?>
				<div class="alert alert-error">
					<?php echo Yii::app()->user->getFlash('error'); ?>
				</div>
			<?php endif; ?>
		</div>
		<div class="kolom-2-kiri-sedikit" align="center">
			<div class="foto-profil">
			<img src="<?php echo $model->foto==null ? Yii::app()->request->baseUrl.'/images/profil/default.png' : Yii::app()->request->baseUrl.'/images/profil/'.$model->foto.''; ?>" alt="Foto Profil Tidak Diset" />
			<?php if($model->id==Yii::app()->user->id || Yii::app()->user->isSekretaris()) { ?>
			<div class="tombol-foto">
				<a id="tombolfoto" onclick="event.preventDefault(); opsifoto(); return false;" href="#" class="tombol">GANTI FOTO</a>
				<div class="sub-foto">
					<ul>
						<li><a href="#" onclick="event.preventDefault(); uploadfoto(); return false;" >Upload Foto</a></li>
						<?php 
							$foto=UserGantiFoto::model()->findByPk($model->id);
							$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
								'id'=>'userGantiFoto-form',       
								//'enableClientValidation' => true,
								'enableAjaxValidation' => false,
								'type' => 'horizontal',
								'method' => 'post',
								'htmlOptions' => array(
									'enctype' => 'multipart/form-data',
									'style' => 'display:none',
								)
								
							));
							
								echo $form->fileField($foto,'foto',array('size'=>60,'maxlength'=>100, 'style'=>'visibility:hidden', 'onchange'=>'this.form.submit()'));

							$this->endWidget();
						?>
						<?php if(User::model()->findByPk($model->id)->foto!=null){ ?>
						<li><a href="<?php echo Yii::app()->createUrl('/user/removeFoto', array('id'=>$model->id)); ?>">Hapus Foto</a></li>
						<?php } ?>
					</ul>
				</div>
			</div>
			
			<?php } ?>
			</div>
		</div>
		<div class="kolom-2-kanan-banyak">
			<table class="profil">
				<tr>
					<td>Nama Lengkap</td><td>: <?php echo $model->nama; ?></td>
				</tr>
				<tr>
					<td>Riwayat Kelas</td><td>: <?php 
						$dbh=Yii::app()->db;
						$sql="select kelas_id from riwayatkelas where user_id=".$model->id." order by kelas_id";
						$command=$dbh->createCommand($sql);
						$reader=$command->query();
						$arraykelas = array();
						if($reader->getRowCount()!=0){
							while(($row=$reader->read())!==false){
								$arraykelas[] = Kelas::model()->findByPk($row['kelas_id'])->kelas;
							}
							sort($arraykelas);
							foreach($arraykelas as $kelas){
								echo $kelas.", ";
							}
						}else{
							echo "<span class='null'>Tidak diset</span>";
						}
					?></td>
				</tr>
				<tr>
					<td>Angkatan</td><td>: <?php echo Angkatan::model()->findByPk($model->angkatan_id)->angkatan; ?></td>
				</tr>
				<tr>
					<td>Agama</td><td>: <?php echo Agama::model()->findByPk($model->agama_id)->agama; ?></td>
				</tr>
				<tr>
					<td>Email Aktif</td><td>: <?php echo $model->email==null ? "<span class='null'>Tidak diset</span>" : $model->email; ?></td>
				</tr>
				<tr>
					<td>Nomor HP</td><td>: <?php 
						$dbh=Yii::app()->db;
						$sql="select nomorHp from nomorhp where user_id=".$model->id;
						$command=$dbh->createCommand($sql);
						$reader=$command->query();
						if($reader->getRowCount()!=0){
							while(($row=$reader->read())!==false){
								echo $row['nomorHp'].", ";
							}
						}else{
							echo "<span class='null'>Tidak diset</span>";
						}
					?></td>
				</tr>
				<tr>
					<td>Asal Daerah</td><td>: <?php echo $model->asalDaerah; ?></td>
				</tr>
				<tr>
					<td>Penempatan</td><td>: <?php echo $model->penempatan==null ? "<span class='null'>Tidak diset</span>" : $model->penempatan; ?></td>
				</tr>
				<tr>
					<td style="padding-top:5px;">Riwayat Divisi</td><td><?php 
						$dbh=Yii::app()->db;
						$sql="select divisi_id, jabatan_id, kepengurusan_id from riwayatdivisi where user_id=".$model->id." and divisi_id>2 order by kepengurusan_id";
						$command=$dbh->createCommand($sql);
						$reader=$command->query();
						if($reader->getRowCount()!=0){
							echo "<ol>";
							while(($row=$reader->read())!==false){
								echo "<li>".Divisi::model()->findByPk($row['divisi_id'])->divisi ." sebagai ". Jabatan::model()->findByPk($row['jabatan_id'])->jabatan ." (".Kepengurusan::model()->findByPk($row['kepengurusan_id'])->kepengurusan.") </li>";
							}
							echo "</ol>";
						}else{
							echo ": <span class='null'>Tidak diset</span>";
						}
					?></td>
				</tr>
				<tr>
					<td style="padding-top:5px;">Media Sosial</td><td><?php 
						$dbh=Yii::app()->db;
						$sql="select judul,isi from mediasosial where user_id=".$model->id." order by judul";
						$command=$dbh->createCommand($sql);
						$reader=$command->query();
						if($reader->getRowCount()!=0){
							echo "<ol>";
							while(($row=$reader->read())!==false){
								echo "<li>".$row['judul'] ." : ". $row['isi']." </li>";
							}
							echo "</ol>";
						}else{
							echo ": <span class='null'>Tidak diset</span>";
						}
					?></td>
				</tr>
			</table>
		</div>
		<div class="clear"></div>
		<div align="right" class="kolom-1" style="margin-top:10px">
			<?php if($model->id==Yii::app()->user->id || Yii::app()->user->isSekretaris()) { ?>
				<?php if(Yii::app()->user->isSekretaris()) { ?>
					<a href="<?php echo Yii::app()->createUrl('/user/create'); ?>" class="tombol">TAMBAH ANGGOTA</a>
				<?php }if($model->id==Yii::app()->user->id) { ?>
					<a href="<?php echo Yii::app()->createUrl('/user/updatePassword'); ?>" class="tombol">UBAH PASSWORD</a>
				<?php }if( Yii::app()->user->isSekretaris() && User::model()->findByPk($model->id)->levelUser_id!=1){ ?>
					<a href="<?php echo Yii::app()->createUrl('/user/resetPassword', array('id'=>$model->id)); ?>" class="tombol">RESET PASSWORD</a>
				<?php }else if(Yii::app()->user->isAdmin()){ ?>
					<a href="<?php echo Yii::app()->createUrl('/user/resetPassword', array('id'=>$model->id)); ?>" class="tombol">RESET PASSWORD</a>
				<?php } ?>
				<a href="<?php echo Yii::app()->createUrl('/user/updateProfil', array('id'=>$model->id)); ?>" class="tombol">EDIT PROFIL</a>
			<?php } ?>
		</div>
		
	</div>
</div>

<script type="text/javascript">
	jQuery(function() {
		jQuery(".tombol-foto").fadeTo("fast",0.8);
		jQuery('.sub-foto').hide();
		jQuery('.foto-profil').hover(function() {
			 jQuery(this).find('.tombol-foto').fadeTo("fast",1);
		}, function() {
			if(open){
				jQuery(this).find('.tombol-foto').slideUp('medium',function(){
					jQuery('.tombol-foto').slideDown('slow');
					open = false;
				  }); 
			}
			jQuery(this).find('.tombol-foto').fadeTo("fast",0.8);
			jQuery('.sub-foto').hide();
		});
		
	});

</script>
<?php
	Yii::app()->clientScript->registerScript('gantifoto', "
	var open = false;
	function opsifoto(){
		open = true;
		$('.tombol-foto').children('.sub-foto').slideToggle('slow');
	}
	
	function uploadfoto(){
		$('#UserGantiFoto_foto').trigger('click');
		return false;
	}
	", CClientScript::POS_END);
?>